use prost::Message;
mod prost_gen;
use prost_gen::example;
use proto_ext::MessageExt;

pub fn main() {
    let mut buf = Vec::new();

    let mut request = example::LoginInfo::default();
    request.name = "hello11".to_string();
    request.password = "password11".to_string();
    let _ = request.encode_length_delimited(&mut buf);

    let mut request1 = example::LoginInfo::default();
    request1.name = "hello22".to_string();
    request1.password = "password22".to_string();
    let _ = request1.encode_length_delimited(&mut buf);

    let s = "hahaha11".to_owned();
    let _ = s.encode_length_delimited(&mut buf);

    let s2 = "hahaha22".to_owned();
    let _ = s2.encode_length_delimited(&mut buf);

    let s3 = "hahaha33".to_owned();
    let _ = s3.encode_length_delimited(&mut buf);

    //let mut cursor = &buf[..]; // 类型是 &[u8]
    let mut cursor = std::io::Cursor::new(buf);

    let request2 = example::LoginInfo::decode_length_delimited(&mut cursor).unwrap();
    println!("{:?}", request2);

    let request22 = example::LoginInfo::decode_length_delimited(&mut cursor).unwrap();
    println!("{:?}", request22);

    let (s1, s2,s3) =
        <(String, String,String)>::decode_length_delimited(&mut cursor).unwrap();

    println!("{:?} {:?} {:?}", s1, s2,s3);
}
